<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>存储数据</button>
    <button>删除数据</button>
    <button>获取数据</button>
    <button>删除所有数据</button>

    <script>
        var buttons = document.querySelectorAll('button');
        for (var i = 0; i < buttons.length; i++) {
            var button = buttons[i];
            switch (i) {
                    case 0:
                    button.addEventListener('click', function() {
                        localStorage.setItem('i--name',i);
                    });
                        
                        break;
                    case 1:
                    button.addEventListener('click', function() {
                        localStorage.removeItem('i--name',i);
                    });
                        
                        break;
                    case 2:
                    button.addEventListener('click', function() {
                        localStorage.getItem('i--name');
                    });
                        
                        break;
                    case 3:
                    button.addEventListener('click', function() {
                        localStorage.clear();
                    });
                        
                        break;
                
                    default:
                        break;
                }
            
        }
    </script>
</body>
</html>